home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Examples / IndexingKit / ToDoList / DailyBread.m < prev    next >
Encoding:
Text File  |  1993-02-16  |  2.4 KB  |  135 lines

  1. /*
  2. DailyBread.m - Copyright (c) 1992 NeXT Computer, Inc.
  3.  
  4. You may freely copy, distribute and reuse the code in this example.
  5. NeXT Computer, Inc. disclaims any warranty of any kind, expressed or implied, 
  6. as to its fitness for any particular use.
  7. */
  8.  
  9. #import    <appkit/appkit.h> 
  10. #import    <objc/hashtable.h>
  11. #import    "DailyBread.h"
  12. #import    "IXStringSearch.h"
  13.  
  14. @implementation DailyBread
  15.  
  16. - initForDate:(const char *)theDate
  17. {
  18.     int   i;
  19.  
  20.     [super init];
  21.     _changed = YES;
  22.     _theDate = NXCopyStringBuffer(theDate);
  23.     upperLimit = 7;
  24.     for (i = 0; i < DBR_MAXFIELDS; i++) {
  25.     doneFields[i] = TRUE;
  26.     _number[i] = NXCopyStringBuffer("");
  27.     }
  28.  
  29.     _theStringValue = NXCopyStringBuffer("");
  30.     return self;
  31. }
  32.  
  33. - free
  34. {
  35.     int  i;
  36.  
  37.     free(_theDate);
  38.     for (i = 0; i < DBR_MAXFIELDS; i++)
  39.     free(_number[i]);
  40.  
  41.     free(_theStringValue);
  42.     return[super free];
  43. }
  44.  
  45. - (char *)theDate
  46. {
  47.     return _theDate;
  48. }
  49.  
  50. - setNumber:(int)i to:(const char *)aString
  51. {
  52.     _changed = YES;
  53.     if (strlen(_number[i]) > 0)
  54.     free(_number[i]);
  55.  
  56.     _number[i] = NXCopyStringBuffer(aString ? aString : "");
  57.     return self;
  58. }
  59.  
  60. - (char *)number:(int)i
  61. {
  62.     return (i < DBR_MAXFIELDS) ? _number[i] : "";
  63. }
  64.  
  65. - setDone:(int)i to:(int)yn
  66. {
  67.     _changed = YES;
  68.     doneFields[i] = yn ? YES : NO;
  69.     return self;
  70. }
  71.  
  72. - (int)done:(int)i
  73. {
  74.     return (i < DBR_MAXFIELDS) ? doneFields[i] : 0;
  75. }
  76.  
  77. - (float)textGrayOfNumber:(int)i
  78. {
  79.     return textGrays[i];
  80. }
  81.  
  82. - setNumber:(int)i textGray:(float)gVal
  83. {
  84.     textGrays[i] = gVal;
  85.     return self;
  86. }
  87.  
  88. - (const char *)stringValue
  89. {
  90.     char   *theResult;
  91.     int    sLength, i;
  92.  
  93.     sLength = 0;
  94.     if (_changed == YES) {
  95.     if (strlen(_theStringValue) > 0)
  96.         free(_theStringValue);
  97.  
  98.     for (i = 0; i < upperLimit; i++)
  99.         sLength += (2+strlen(_number[i]));
  100.  
  101.     theResult = (char *)malloc(sLength+20);
  102.     strcpy(theResult, _theDate);
  103.     strcat(theResult, "\n");
  104.     for (i = 0; i < upperLimit; i++) {
  105.         strcat(theResult, _number[i]);
  106.         strcat(theResult, "\n");
  107.     }
  108.  
  109.     _theStringValue = theResult;
  110.     _changed = NO;
  111.     };
  112.  
  113.     return _theStringValue;
  114. }
  115.  
  116. - (const char *)midlingStringValueFor:(const char *)aWord
  117. {
  118.     IXBMTable    *theEngine;
  119.  
  120.     // yup, this is undocumented. it does what any BoyerMoore search might do.*/
  121.     theEngine = IXBMCompile(aWord, YES);
  122.     return IXBMMatch(_theStringValue, strlen(_theStringValue), theEngine);
  123. }
  124.  
  125. - source:aSource didReadRecord:(unsigned)record
  126. {
  127.     return self;
  128. }
  129.  
  130. - source:aSource willWriteRecord:(unsigned)record
  131. {
  132.     return self;
  133. }
  134.  
  135.